/*
 *      net_view.cpp
 *      
 *      Copyright 2009 AzureSky <AzureSky.fedora@gmail.com>
 *      
 *      This program is free software; you can redistribute it and/or modify
 *      it under the terms of the GNU General Public License as published by
 *      the Free Software Foundation; either version 2 of the License, or
 *      (at your option) any later version.
 *      
 *      This program is distributed in the hope that it will be useful,
 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *      GNU General Public License for more details.
 *      
 *      You should have received a copy of the GNU General Public License
 *      along with this program; if not, write to the Free Software
 *      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 *      MA 02110-1301, USA.
 */

#include "net_view.h"

net_view::net_view(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>& refGlade):
	Gtk::TreeView(cobject),
	refXml(refGlade)
{
	init_view();
	net_title();
	net_read();
}

net_view::~net_view()
{
}

void net_view::init_view()
{
	p_net_model = Gtk::ListStore::create(net_list);
	set_model(p_net_model);
}

void net_view::net_title()
{
  	append_column ("协议", net_list.m_proto);
	append_column ("本地地址", net_list.m_local);
	append_column_numeric ("端口", net_list.m_local_port,"%d");
	append_column ("远程地址", net_list.m_foreign);
	append_column_numeric ("端口", net_list.m_remote_port,"%d");
	append_column ("状态", net_list.m_stat);
}

void net_view::net_read()
{
	the_list.refresh();
	net_list::iterator it;
	for(it = the_list.begin();it != the_list.end();++it){
		add_row(it);	}
}

void net_view::net_refresh()
{
		p_net_model -> clear();
		net_read();
}

void net_view::add_row(net_list::iterator it)
{
    	Gtk::TreeModel::Row row = *(p_net_model -> append());
	row[net_list.m_proto] = it->type;
  	row[net_list.m_local] = it->local_ip;
  	row[net_list.m_local_port] = it->local_port;
  	row[net_list.m_foreign] = it->remote_ip;
  	row[net_list.m_remote_port] = it->remote_port;
  	row[net_list.m_stat] = it->status;
}
